package leetcode.code165;

public class Solution extends Solution165 {

	@Override
	public int compareVersion(String version1, String version2) {
		int len1 = version1.length();
		int len2 = version2.length();
		int p1 = 0;
		int p2 = 0;
		int ver1 = 0;
		int ver2 = 0;
		char v1 = 'a';
		char v2 = 'b';
		while (p1 < len1 && p2 < len2) {
			ver1 = 0;// 待比较
			ver2 = 0;// 待比较
			do {
				v1 = version1.charAt(p1);
				if ((ver1 > 0 || v1 != '0') && v1 != '.') {
					ver1 = ver1 * 10 + (v1 - 48);
				}
				p1++;
			} while (v1 != '.' && p1 < len1);
			do {
				v2 = version2.charAt(p2);
				if ((ver2 > 0 || v2 != '0') && v2 != '.') {
					ver2 = ver2 * 10 + (v2 - 48);
				}
				p2++;
			} while (v2 != '.' && p2 < len2 );
			if (ver1 > ver2)
				return 1;
			else if (ver1 < ver2)
				return -1;
		}
		while (p1 < len1) {
			v1 = version1.charAt(p1);
			if (v1 != '0' && v1 != '.') {
				return 1;
			}
			p1++;
		}
		while (p2 < len2) {
			v2 = version2.charAt(p2);
			if (v2 != '0' && v2 != '.') {
				return -1;
			}
			p2++;
		}
		return 0;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		so.debug5();
	}

}
